<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="__STATIC__/plugins/layui/css/layui.css" media="all">
</head>
<body>
<script src="__STATIC__/plugins/layui/layui.js"></script>
<form method="POST" action="" accept-charset="UTF-8" class="layui-form">
    <input type="hidden" name="data" id="npm">
    <div class="layui-form-item"><label for="name" class="layui-form-label">问卷名称</label>
        <div class="layui-input-block"><input class="layui-input" id="name" name="name" type="text" value="{$list.name}"></div>
    </div>
    <div class="layui-form-item" >
        <table id="demo" lay-filter="test"></table>
    </div>

    <!---->
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
        <button class="layui-btn layui-btn-primary" type="reset"><a class="layui-layer-btn1">取消</a></button>
    </div>
</form>
</body>
<script>
    layui.use(['form','table'], function () {
        // var form = layui.form;
        // window.$ = layui.$;
        var table=layui.table;

        function checkbox(){
            $("input:checkbox[name='demo']:checked").each(function() { // 遍历name=test的多选框
                $(this).val();
                console.log($(this).val());
            });
        }

        table.render({
            elem: '#demo'
            ,height: 315
            ,url: '{:url("questionnaire/detail")}' //数据接口
            ,cols: [[ //表头
                {checkbox: true, fixed: true},
                {field: 'id', title: 'ID', width:80, sort: true}
                ,{field: 'name', title: '问题名称', width:200}
                ,{field: 'type', title: '类型', width:80, sort: true}
                ,{field: 'weight', title: '编辑权重', width:100, sort: true,edit: 'text'}
            ]]
        });

        //监听单元格事件
        table.on('edit(demo)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            $.post('{:url("question/edit")}',{id:data.id,field:value,name:field},function(respance){
                layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            });

        });
    });
</script>
</html>